// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.IndexManagement;

public sealed partial class Queries
{
	[JsonInclude, JsonPropertyName("cache")]
	public Elastic.Clients.Elasticsearch.Serverless.IndexManagement.CacheQueries? Cache { get; set; }
}

public sealed partial class QueriesDescriptor : SerializableDescriptor<QueriesDescriptor>
{
	internal QueriesDescriptor(Action<QueriesDescriptor> configure) => configure.Invoke(this);

	public QueriesDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Serverless.IndexManagement.CacheQueries? CacheValue { get; set; }
	private CacheQueriesDescriptor CacheDescriptor { get; set; }
	private Action<CacheQueriesDescriptor> CacheDescriptorAction { get; set; }

	public QueriesDescriptor Cache(Elastic.Clients.Elasticsearch.Serverless.IndexManagement.CacheQueries? cache)
	{
		CacheDescriptor = null;
		CacheDescriptorAction = null;
		CacheValue = cache;
		return Self;
	}

	public QueriesDescriptor Cache(CacheQueriesDescriptor descriptor)
	{
		CacheValue = null;
		CacheDescriptorAction = null;
		CacheDescriptor = descriptor;
		return Self;
	}

	public QueriesDescriptor Cache(Action<CacheQueriesDescriptor> configure)
	{
		CacheValue = null;
		CacheDescriptor = null;
		CacheDescriptorAction = configure;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (CacheDescriptor is not null)
		{
			writer.WritePropertyName("cache");
			JsonSerializer.Serialize(writer, CacheDescriptor, options);
		}
		else if (CacheDescriptorAction is not null)
		{
			writer.WritePropertyName("cache");
			JsonSerializer.Serialize(writer, new CacheQueriesDescriptor(CacheDescriptorAction), options);
		}
		else if (CacheValue is not null)
		{
			writer.WritePropertyName("cache");
			JsonSerializer.Serialize(writer, CacheValue, options);
		}

		writer.WriteEndObject();
	}
}